package com.zzti.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zzti.dao.EmployeeDao;
import com.zzti.pojo.Employee;

@WebServlet("/UpdateEmployeeServlet")
public class UpdateEmployeeServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		// 进行修改员工信息
		int id = Integer.parseInt(request.getParameter("id"));
		String name = request.getParameter("name");
		String sex = request.getParameter("sex");
		int age = Integer.parseInt(request.getParameter("age"));
		String department = request.getParameter("department");
		String type = request.getParameter("type");
		int year = Integer.parseInt(request.getParameter("year"));
		Employee employee = new Employee(id, name, sex, age, department, type, year);
		EmployeeDao employeeDao = new EmployeeDao();
		int i = employeeDao.updateEmployeeById(employee);
		if (i == 1) {
			response.sendRedirect(request.getContextPath() + "/FindEmployee");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
